﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Threading;

namespace SA_Monopoly.Presentation
{
    class tokenImgsManager
    {
        List<Image> list;
        public int prevDisplayed;
        public int currentDisplayed;
        int step;
        DispatcherTimer timer;

        public tokenImgsManager(List<Image> list)
        {
            this.list = list;
            currentDisplayed = 0;
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(100);
            timer.Tick += new EventHandler(timer_tick);
        }

        void timer_tick(object sender, EventArgs e)
        {
            step++;

            if (step >= currentDisplayed)
            {
                timer.Stop();
            }

            if (step > 0 && step <= 39)
            {
                list[step - 1].Opacity = 0;
                list[step].Opacity = 1;
            }
        }

        public void setCurrentDisplay(int index)
        {
            if (index < currentDisplayed)
            {
                list[currentDisplayed].Opacity = 0;
                prevDisplayed = 0;
                currentDisplayed = index;
            }
            else
            {
                prevDisplayed = currentDisplayed;
                currentDisplayed = index;
            }

            

            step = prevDisplayed;

            timer.Start();            
        }
    }
}
